<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins"
	value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>入库信息</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${BasePath}/res/js/common/jquery.validate.method.js" type="text/javascript"></script>
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${BasePath}/res/js/common/ajaxfileupload.js" type="text/javascript"></script>

<c:set var="isAddPage" value="${stockInViewType == 1}" />
<c:set var="isAduitPage" value="${stockInViewType == 2}" />
<c:set var="isDetailPage" value="${stockInViewType == 3}" />
<c:set var="isPurBillImportPage" value="${stockInViewType == 4}" />
<c:set var="isBookBillImportPage" value="${stockInViewType == 6}" />
<c:set var="isDefectReturnImportPage" value="${stockInViewType == 9}" />
<c:set var="isPurReturnImportPage" value="${stockInViewType == 11}" />
<c:set var="isTransferImportPage" value="${stockInViewType == 13}" />

<c:set var="isPurchaseBillData" value="${stockIn.stockInType == 1}" />
<c:set var="isBookBillData" value="${stockIn.stockInType == 2}" />
<c:set var="isDefectReturnData" value="${stockIn.stockInType == 3}" />
<c:set var="isPurReturnData" value="${stockIn.stockInType == 4}" />
<c:set var="isTransferData" value="${stockIn.stockInType == 5}" />
<c:set var="isAduitedData" value="${stockIn.stockInState == 1}" />

<style type="text/css">
.l-table-edit {
	
}

.l-table-edit-td {
	padding: 5px;
}

.l-button-submit, .l-button-test {
	height: 25px;
	width: 100px;
	float: left;
	margin-left: 10px;
	padding-bottom: 2px;
}

.l-verify-tip {
	left: 230px;
	top: 120px;
}

.p-tab .s-lab {
	font-size: 6px;
	font-family: "微软雅黑", ​ "宋体", ​Arial, ​sans-serif;
}

input.l-textarea {
	width: 170px;
	height: 20px;
	font-size: 6px;
}

span {
	font-size: 13px;
}

.navbar {
	height: 20px;
	border-bottom: #E6E6E6 solid 1px;
	line-height: 20px;
}

select {
	margin-right: 10px;
	width: 170px;
}

#searchbar {
	margin-bottom: 10px;
	margin-left: 15px;
}

ul {
	list-style: none;
	border: 1px solid #DDDDDD;
	width: 400px;
	float: left;
}

.li_ls {
	float: left;
	width: 30%;
	margin: 5px;
	word-break: keep-all; /* 不换行 */
	white-space: nowrap; /* 不换行 */
	overflow: hidden;
	text-overflow: ellipsis;
}

.l-button-search {
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}

.inputSize {
	width: 170px;
}
</style>
</head>
<body style="padding: 10px">
	<div class="navbar">
		<span>您当前的位置：</span>
		<c:choose>
		<c:when test="${!isAduitedData and isAduitPage}">
			出入库管理 &gt;商品入库管理>&gt;入库
		</c:when>
		<c:when test="${isAddPage}">
			出入库管理 &gt;商品入库管理>&gt;新增入库
		</c:when>
		<c:when test="${isPurBillImportPage}">
			采购管理 &gt;采购单管理>&gt;采购单入库
		</c:when>
		<c:when test="${isPurReturnImportPage}">
			采购管理 &gt;采购单退货管理>&gt;换货入库
		</c:when>
		<c:when test="${isBookBillImportPage}">
			多渠道订单管理 &gt;订单退换货管理>&gt;退货入库
		</c:when>
		<c:when test="${isDefectReturnImportPage}">
			商品管理 &gt;次品退货管理>&gt;换货入库
		</c:when>
		<c:when test="${isTransferImportPage}">
			商品库存管理 &gt;库存调拨> &gt;生成入库单
		</c:when>
		<c:otherwise>
			出入库管理 &gt;商品入库管理>&gt;详细
		</c:otherwise>
		</c:choose>
	</div>
	<form name="form1" method="post" action="approveStockIn.do" id="form1"
		onsubmit="return setGridData()">
		<table border=0 cellpadding="0" cellspacing="0"
			class="l-table-edit p-tab" style="height: 100%; width: 100%">
			<tr style="height: 5%">
				<td>
					<table style="width: 80%" border=0>
					<c:if test="${isAduitPage || isDetailPage}">
						<tr>
							<td style="width: 50%"><span>入库单号&nbsp;:</span>&nbsp; 
								<span id="stockInNo">${stockIn.stockInNo}</span>
							</td>
							<td colspan="2">
								<span>仓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;库:&nbsp;&nbsp;</span>&nbsp;
								<span id="whNo" style="display: none">${stockIn.whNo}</span>
								<span id="whName">${stockIn.whName}</span>
							</td>
						</tr>
						</c:if>
						<tr style="height: 9px">
							<td colspan="2"></td>
						</tr>
						<tr>
							<td>
								<span>入库类型&nbsp;:</span>
								<span>
									<c:choose>
										<c:when test="${stockIn.stockInType==1}">货品采购入库</c:when>
										<c:when test="${stockIn.stockInType==2}">订单退换货入库</c:when>
										<c:when test="${stockIn.stockInType==3}">次品退换货入库</c:when>
										<c:when test="${stockIn.stockInType==4}">采购退换货入库</c:when>
										<c:when test="${stockIn.stockInType==5}">调拨入库</c:when>
										<c:when test="${stockIn.stockInType==6}">其他入库</c:when>
										<c:otherwise></c:otherwise>
									</c:choose>
									<span id="stockInType" style="display: none;">${stockIn.stockInType}</span>
								</span>
							</td>
							<td>
								<c:if test="${!isBookBillImportPage && !isTransferImportPage and !isTransferData}">
									<span>供&nbsp;应&nbsp;商&nbsp;:</span>&nbsp; 
									<span id="supName">${stockIn.supName}</span>
									<span id="supNo" style="display: none;">${stockIn.supNo}</span>
								</c:if>
							</td>
						</tr>
						<tr style="height: 10px">
							<td colspan="2"></td>
						</tr>
						<tr>
							<td>
								<span id="purNameTitle"> 
									<c:choose>
										<c:when test="${isPurchaseBillData}">采购单号&nbsp;:&nbsp;</c:when>
										<c:when test="${isBookBillData}">订单编号&nbsp;:&nbsp;</c:when>
										<c:when test="${isDefectReturnData}">次品退货编号&nbsp;:&nbsp;</c:when>
										<c:when test="${isPurReturnData}">采购退货编号&nbsp;:&nbsp;</c:when>
										<c:when test="${isTransferData}">调拨编号&nbsp;:&nbsp;</c:when>
										<c:otherwise></c:otherwise>
									</c:choose>
								</span> 
								<c:choose>
									<c:when test="${isPurchaseBillData}">
										<span id="purNo">${stockIn.purNo}</span>
									</c:when>
									<c:otherwise>
										<span id="stockInTypeNo">${stockIn.stockInTypeNo}</span>
										<span id="purNo" style="display: none;">${stockIn.purNo}</span>
									</c:otherwise>
								</c:choose>
							</td>
							<c:choose>
								<c:when test="${isPurchaseBillData}">
									<td id="purNameValue">
										<span>采购名称:</span> 
										<span>${stockIn.purName}</span>
									</td>
								</c:when>
								<c:when test="${!isAduitPage and !isBookBillImportPage}">
									<td>
										<span>仓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;库:&nbsp;&nbsp;</span>&nbsp;
										<span id="whNo" style="display: none">${stockIn.whNo}</span>
										<span id="whName">${stockIn.whName}</span>
									</td>
								</c:when>
								<c:otherwise></c:otherwise>
							</c:choose>
						</tr>
					</table> <br>
				</td>
			</tr>
			<tr style="height: 50%">
				<td>
					<div id="maingrid" style="margin: 0; padding: 0"></div>
					<div style="display: none;"></div>
				</td>
			</tr>
			<tr style="height: 15%">
				<td style="padding-left: 40%; top: 80%">
					 <!-- <div style="<c:if test="${isAduitedData}">display:none;</c:if>"> -->
						<c:choose>
							<c:when test="${!isAduitedData and isAduitPage}">
								<input type="button" value="入库"
									onclick="approveStockIn('${stockIn.stockInNo}')" id="Button1"
									class="l-button l-button-submit" />
							</c:when>
							<c:when test="${!isDetailPage}">
								<input type="button" value="入库" onclick="addStockIn()"
									id="Button1" class="l-button l-button-submit" />
							</c:when>
						</c:choose>
					<input type="button" value="<c:if test = "${!isAduitedData}">取消</c:if><c:if test = "${isAduitedData}">返回</c:if>" name="tests"  id="tests" class="l-button l-button-test" />
				</td>
			</tr>
		</table>
	</form>
<div id="importBarCodeDiv" style="display:none"></div>
<script type="text/javascript">
//页面常量
		var g = null;
		var basePath = '${BasePath}';
		var whData = [];
		var isAddPage = ${isAddPage};
		var isAduitPage = ${isAduitPage};
		var isDetailPage = ${isDetailPage};
		var isPurBillImportPage = ${isPurBillImportPage};
		var isBookBillImportPage = ${isBookBillImportPage};
		var isPurReturnImportPage = ${isPurReturnImportPage};
		var isTransferImportPage = ${isTransferImportPage};
		var isPurchaseBillData = ${isPurchaseBillData};
		var isBookBillData = ${isBookBillData};
		var isDefectReturnData = ${isDefectReturnData};
		var isPurReturnData = ${isPurReturnData};
		var isTransferData = ${isTransferData}
		var parentTabId = ${tabId}; 
		var tabId = window.top.tab.getSelectedTabItemID();
		var ajaxAddUrl = basePath + "/stockmanage/StockController/addStockIn.do";
		var ajaxUploadUrl = basePath +  "/stockmanage/productBarCodeContrller/importBarCode.do";
		var ajaxApproveUrl = basePath + "/stockmanage/StockController/approveStockIn.do";
		var queryBarCodeUrl = basePath + '/stockmanage/productBarCodeContrller/pageFinderProductBarCode.do';
		var deleteBarCodeUrl = basePath + '/stockmanage/productBarCodeContrller/deleteProductBarCode.do';
		var columns = [{display : '货品编号',name : 'prodNo'}, 
			           {display : '商品名称',name : 'commoName'}, 
			           {display : '货品条码',name : 'prodBarCode'}, 
			           {display : '货品规格',name : 'specName',
							render : function(rowdata, rowindex, value) {
								if(value == "" || value == null){
									rowdata.specName = rowdata.specification
								}
								return rowdata.specName
							}}, 
			           {display : '总数量',name : 'prodTotal'}, 
			          ];
		var gridArgs = {
				columns : columns,
				pageSize : 30,
				width : '100%',
				height : '90%',
				dataType : 'server',
				dataAction : 'server',
				pagesizeParmName : 'pageSize',
				enabledEdit : true
			};
//复用方法
		function operateSuccess() {
			window.top.tab.selectTabItem(parentTabId);
			window.top.tab.reload(parentTabId);
			window.top.tab.removeTabItem(tabId);
		}

		function setColumns(columns,index,columnsBody,editType) {
			if (index > columns.length) {
				index = columns.length;
			}else{
				for (var i = columns.length ; i > index; i++) {
					columns[i] = columns[i-1];
				}
			}
			columns[index] = columnsBody;
			if(editType != null){
				setColumnsIsEdit(columnsBody,editType)
			}
		}
		
		function setColumnsIsEdit(columnsBody,editType){
			columnsBody.editor = {type : editType};
			columnsBody.render = function(rowdata, rowindex, value) {
				if (value == '' || value == null) {
					if(editType == 'int'){
						return "<font style='color: blue;font-size: 12px;'>0</font>";
					}else{
						return "<font style='color: blue;font-size: 12px;'>请输入</font>";
					}
				}
				return value;
			};
		}
//页面拼接元素
		
		$("#tests").click(function() {
			operateSuccess();
		});

		function deleteRow(index) {
			$.ligerDialog.confirm('确定删除', function(yes) {
				if (yes) {
					g.deleteRow(index);
				}
			});
		}
		
		function createGrid(){
			gridArgs.columns = columns;
			g = $("#maingrid").ligerGrid(gridArgs);	
		}

		
		function toImportCode(index) {
        	 $("#importBarCodeDiv").html('<input type="file" id="fileupload" name="barCodeFile" onchange="importBarCode('+index+')"/>');
        	 g.select(index);
        	 $("#fileupload").click(); 
	    }
	      
	//初始化相关		
	$(function () {
		initProductRelatedData()
	});

	function initProductRelatedData(){
		if (isAduitPage == true) {//入库审核初始化
			gridArgs.usePager = false;
			gridArgs.onBeforeSubmitEdit = onBeforeSubmitEdit;
			if(isTransferData == true){
				setColumns(columns,columns.length, {display : '良品数量',name : 'qualifiedQuantity'});
				setColumns(columns,columns.length, {display : '描述',name : 'prodDesc'},'text');
				setColumns(columns,columns.length, {display : '操作',width:180 ,name : 'productCodeState',
					render : function(rowdata, rowindex, value) {
						var result = "";
						if(value == 1){
							result += "<a href='javascript:queryImportCode("+rowindex+ ")'>查看条形码</a>&nbsp;&nbsp;";
						}else if(value == 2){
							result += "<a href='javascript:queryPurInfo("+rowindex+ ")'>查看采购单</a>&nbsp;&nbsp;";
						}
						return result
					}
				});
				//ajaxApproveUrl = basePath + "/stockmanage/StockController/approveStockInForTransfer.do";
			}else{
				setColumns(columns,columns.length, {display : '良品数量',name : 'qualifiedQuantity'},'int');
				if(!isBookBillData){
					setColumns(columns,columns.length, {display : '次品数量',name : 'defectiveQuantity'},'int');
					setColumns(columns,columns.length, {display : '次品原因',name : 'defectiveReason'},'text');
				}
				setColumns(columns,columns.length, {display : '描述',name : 'prodDesc'},'text');
				setColumns(columns,columns.length, {display : '操作',width:180 ,name : 'productCodeState',
					render : function(rowdata, rowindex, value) {
						var result = "";
						if(value == 1){
							result += "<a href='javascript:deleteImportCode("+rowindex+")'>删除条形码</a>&nbsp;&nbsp;";
							result += "<a href='javascript:queryImportCode("+rowindex+ ")'>查看条形码</a>&nbsp;&nbsp;";
						}else{
							result += "<a href='javascript:toImportCode("+rowindex+ ")'>导入条形码</a>&nbsp;&nbsp;";
						}
						return result
					}
				});
				var downloadFile = "<a style = 'color:black' href='${BasePath}/stockmanage/productBarCodeContrller/dowanloadTemplet.do'>下载条形码模板</a>";
				gridArgs.toolbar= {items: [{ text:downloadFile, click: function(){}, icon: "down" }]}		
			}
			gridArgs.url = basePath + "/stockmanage/StockController/ajaxPageFinderStockInDetail.do?stockInNo=${stockIn.stockInNo}";
			createGrid();
		}else if (isDetailPage == true) {//入库详情初始化
			if(isPurchaseBillData){
				 setColumns(columns,columns.length, {display : '成本价格',name : 'prodCost'})
			}
			setColumns(columns,columns.length, {display : '良品数量',name : 'qualifiedQuantity'})
			setColumns(columns,columns.length, {display : '次品数量',name : 'defectiveQuantity'})
			setColumns(columns,columns.length, {display : '描述',name : 'prodDesc'})
			setColumns(columns,columns.length, {display : '次品原因',name : 'defectiveReason'});
			setColumns(columns,columns.length, {display : '条形码',width:180 ,name : 'productCodeState',
				render : function(rowdata, rowindex, value) {
					if(value == 1){
						return "<a href='javascript:queryImportCode("+ rowindex + ")'>查看条形码</a>&nbsp;&nbsp;";
					}else{
						return "暂无条形码";
					}
				}
			});
			gridArgs.url = basePath + "/stockmanage/StockController/ajaxPageFinderStockInDetail.do?stockInNo=${stockIn.stockInNo}";
			createGrid();
		}else if (isPurBillImportPage == true) {//采购入库初始化
			setColumns(columns,columns.length, {display : '成本价格',name : 'prodCost'})
			setColumns(columns,columns.length, {display : '仓库',name : 'whName'})
			gridArgs.url = basePath + "/manager/purchase/orders/purchaseOrderList_ToWarehouse.do?poNo=${stockIn.purNo}";
			ajaxAddUrl = basePath + "/stockmanage/StockController/addStockInForPurchaseOrder.do";
			createGrid();
		}else if (isBookBillImportPage == true) {//订单入库初始化
			setColumns(columns,columns.length, {display : '供应商',name : 'supName'});
			var wh = { display: '仓库', name: 'whNo',editor:{
		      	  	type:'select',
		    	  	data: getHwData(),
		    	  	valueField:"whNo",
		    	  	textField:"whName"
	      		 },
	             render: function (record, rowindex, value, column){
	            	 if(value == null || value == ''){
		         		  record.whNo =  whData[0]['whNo'];
			          	  record.whName = [0]['whName'];
			          	  return whData[0]['whName'];
		         	   }
		 	           for (var i = 0; i < whData.length; i++){
		 	        	  if (whData[i]['whNo'] == value){
		  	            	   record.whNo =  whData[i]['whNo'];
		  	            	   record.whName =  [i]['whName'];
		  	                   return whData[i]['whName'];
		  	               }
		 	           }
	  	       } 
	       	}
			setColumns(columns,columns.length, wh);
			ajaxAddUrl = basePath + "/stockmanage/StockController/addStockInForBookReturnBill.do";
			gridArgs.url = basePath + "/stockmanage/StockController/getBookReturnProduct.do?channelOrderId=${stockIn.stockInTypeNo}";
			createGrid();
		}else if (isDefectReturnData == true) {//次品换货入库初始化
			var dataString = '${stockInProduct}';
			createGrid();
			g.addRow(eval("("+dataString+")").stockInProductVo);
			ajaxAddUrl = basePath + "/stockmanage/StockController/addStockInForDefectReplce.do";
		}else if (isPurReturnImportPage == true) {
			ajaxAddUrl = basePath + "/stockmanage/StockController/addStockInForPurReturnBill.do";
			gridArgs.url = basePath + "/manager/purchaseReturn/orders/purchaseOrderList_ToWarehouse.do?puNo=${stockIn.stockInTypeNo}";
			createGrid();
		}else if (isTransferImportPage == true) {
			gridArgs.url = girdUrl = basePath + "/stockmanage/StockController/getTransferProduct.do?stockInTypeNo=${stockIn.stockInTypeNo}";
			ajaxAddUrl = basePath + "/stockmanage/StockController/addStockInForTransfer.do";
			columns = [{display : '货品编号',name : 'prodNo',render : function(rowdata, rowindex, value) {
			            	rowdata.whNo = $('#whNo').html();
			            	return value;
			           }},  
			           {display : '商品名称',name : 'commoName'}, 
			           { display: '货品条码', name: 'prodBarCode',render : function(rowdata, rowindex, value) {
			            	rowdata.prodBarCode = rowdata.prodNo;
			            	return rowdata.prodBarCode;
			            }}, 
			           {display : '货品规格',name : 'specName',
							render : function(rowdata, rowindex, value) {
								if(value == "" || value == null){
									rowdata.specName = rowdata.specification
								}
								return rowdata.specName
							}}, 
			           { display: '供应商', name: 'supName'},
			           {display : '总数量',name : 'prodTotal',render : function(rowdata, rowindex, value) {
			            	rowdata.prodTotal = rowdata.stockoutQuantity;
			            	rowdata.qualifiedQuantity = rowdata.stockoutQuantity;
			            	rowdata.defectiveQuantity = defectiveQuantity = 0;
			            	rowdata.pre
			            	return  rowdata.prodTotal;
			            }}, 
			          ];
			createGrid();
		}
	}
	function getAddData() {
   		var returnData = {};
   		var products = g.getData();
   		returnData.products = JSON.stringify(products);
		if($('#stockInNo').html() != null){
			returnData.stockInNo = $('#stockInNo').html()
		}
		if($('#whNo').html() != null){
			returnData.whNo = $('#whNo').html()
 		}
		if($('#purNo').html() != null){
			returnData.purNo = $('#purNo').html()
		}
		if($('#supNo').html() != null){
			returnData.supNo = $('#supNo').html()
		}
		if($('#supName').html() != null){
			returnData.supName = $('#supName').html()
		}
		if($('#stockInType').html() != null){
			returnData.stockInType = $('#stockInType').html()
		}
		if($('#stockInTypeNo').html() != null){
			returnData.stockInTypeNo = $('#stockInTypeNo').html()
		}
		return returnData;
	}

	function vailData(){
		var data = g.getData();
		var result = checkProductQuantity(data);
		return result;
	}
	function checkProductQuantity(data){
		for(i = 0;i < data.length; i++){
			var prodTotal = data[i].prodTotal;
			var qualifiedQuantity = data[i].qualifiedQuantity == null ? 0: data[i].qualifiedQuantity;
			var defectiveQuantity = data[i].defectiveQuantity == null ? 0: data[i].defectiveQuantity;
			var baseHint = "入库单内编号【"+data[i].prodNo+"】的商品【"+data[i].commoName+"】";
			if(prodTotal == 0){
				g.select(i);
				window.parent.f_tip(baseHint+"总数等于0,无法入库！");
				return false;
			}else if(qualifiedQuantity + defectiveQuantity != prodTotal){
				g.select(i);
				window.parent.f_tip( baseHint+"入库良品和次品的数量输入有误,无法入库!");
				return false;
			}
		}
		return true;
	}
		
	function onBeforeSubmitEdit(e){ 
		var record = e.record;
		var column = e.column;
		var editValue = e.value;
		if(column.name == "qualifiedQuantity"){
			var prodTotal = record.prodTotal;
			if(editValue > prodTotal){
				e.value = prodTotal - record.defectiveQuantity;
				window.parent.f_tip('输入的良品数量与次品数量的总和必须等于商品总数');
			}else if(editValue < 0){
				e.value = e.record.qualifiedQuantity;
				window.parent.f_tip('请输入不小于0的数');
			}else{
				e.record.defectiveQuantity = prodTotal - editValue;
			}
		}else if(column.name == "defectiveQuantity"){
			var prodTotal = record.prodTotal;
			if(editValue > prodTotal){
				e.value = prodTotal - record.qualifiedQuantity;
				window.parent.f_tip('输入的次品数量与良品数量的总和必须等于商品总数');
			}else if(editValue < 0){
				e.value = e.record.defectiveQuantity;
				window.parent.f_tip('请输入不小于0的数');
			}else{
				e.record.qualifiedQuantity = prodTotal - editValue;
			}
		}
	}
		
	function addStockIn() {
		$.ajax({
			async : false,
			type : 'post',
			dataType : 'text',
			data : getAddData(),
			url : ajaxAddUrl,
			success : function(data) {
				if (data == 'fail') {
					window.parent.f_tip('入库失败');
				} else {
					window.parent.f_tip('入库成功');
					operateSuccess();
				}
			}
		});
	}

	function approveStockIn(no) { //入库审核
		if(vailData()){
			var products = g.getData();
			if (no != null && no != '') {
				$.ajax({
					async : false,
					type : 'post',
					dataType : 'text',
					data : {
						stockInNo : no,
						stockInType : $('#stockInType').html(),
						products : JSON.stringify(products)
					},
					url : ajaxApproveUrl,
					success : function(data) {
						if (data == 'fail') {
							window.parent.f_tip('入库失败');
						} else {
							window.parent.f_tip('入库成功');
							operateSuccess();
						}
					}
				});
			}
		}
	}

	function openAddWindow() { //打开新增窗口
		var m = $.ligerDialog.open({
			title : '新增',
			url : basePath + '/.do',
			height : 550,
			width : 1024,
			isResize : false,
			isDrag : false
		});
		m.show();
	}

	 function getHwData(){  //得到仓库数据
        	$.ajax
            ({
                cache: false,
                async: false,
                type: 'post',
                dataType: 'json',
                data: {},
                url: basePath+"/base/wharehouse/ajaxWhareHouseList.do",
                success: function (data) {
                	whData = data.Rows;
                	var json =  [];
                	for (var i = 0; i < whData.length; i++) {
                		var json2 = {};
                		json2.whNo = whData[i].whNo;
                		json2.whName = whData[i].whName;
    					json[i] = json2;
    				}
                	whData = json;
                }
            });
        	return whData;
        }
	 
	 function queryImportCode(rowindex) { //查询条码
			var stockInNo = $('#stockInNo').html();
			var data = g.getSelectedRow();
			var m = $.ligerDialog.open({
				url:queryBarCodeUrl + '?stockInProductId='+ data.id +'&stockInNo='+ stockInNo,
				title:'查看条形码',
				height:550,
				width:1224,
				isResize: false,
				isDrag: false
		});
		m.show(); 
	 }
		 
	 function importBarCode(index){ //导入条码
          var data = g.getSelectedRow();
          if(data != null){
        	  data = {
        			  stockInNo : $("#stockInNo").html(),
        			  stockInType: $("#stockInType").html(),
        			  stockInTypeNo: $("#stockInTypeNo").html(),
        			  purNo : $("#purNo").html(),
		        	  whNo :  $("#whNo").html(),
					  supNo : $("#supNo").html(),
        			  prodNo : data.prodNo,
        			  commoNo: data.commoNo,
        			  stockInProductId : data.id,
        			  prodQuantity : data.prodTotal
        	  };
	    	  var imgurl = $("#fileupload").val();
	    	  var extend = imgurl.substring(imgurl.lastIndexOf("."), imgurl.length);
	          if (extend != ".xlsx" && extend !=  "xls"){
	        	 window.parent.f_tip("不支持文件类型后缀xls和xlsx外文件导入");
	          }else{
	        	  $.ligerDialog.waitting("正在导入中,请不要关闭当前页面..."); 
	        	  var options = {
	        		url : ajaxUploadUrl,
	        		fileElementId: "fileupload",
	        		secureuri:false,
	        		dataType: 'text',
	        		data:data,
					success: function(result){
						if(result.indexOf('success') > -1){
							g.updateCell('productCodeState', 1, index); 
							window.parent.f_tip('导入成功');
						}else if(result.indexOf('prodQuantityFail') > -1){
							window.parent.f_tip('导入条形码数量不一致');
						}else if(result.indexOf('failMsg:') > -1){
							window.parent.f_tip(result.substring(result.indexOf('failMsg:')+8,result.length-6));
						}else {
							window.parent.f_tip('导入失败');
						}
						$.ligerDialog.closeWaitting();  
					}
	        	  }; 
	        	  $.ajaxFileUpload(options);
	          }
          }
      }
	 function deleteImportCode(index) { //删除条形码
	    	var id = g.getData()[index].id;
	    	$.ligerDialog.confirm('确定删除条形码',
	    		function(yes) {if (yes) {
	    			$.post(
    					deleteBarCodeUrl,
    					{stockInProductId : id},
    					function(data) {
    						if (data == 'success') {
    							g.updateCell('productCodeState', 0, index); 
    							window.parent.parent.f_tip('删除成功');
    						} else if (data == 'fail') {
    							window.parent.parent.f_tip('删除失败');
    						}
    					}
	    			);
	    		};
	    	});
	    }
	 
	 function queryPurInfo(rowindex) { //查看选择的采购单
			var data = g.getSelectedRow();
			var url = basePath + '/stockmanage/StockOutPurInfo/toQueryStockOutPurInfo.do?stockOutTypeNo='+ $("#stockInTypeNo").html() +'&prodNo='+ data.prodNo;
			var m = $.ligerDialog.open({
					title:'查看选择的采购单',
					url:url,
					height:550,
					width:1224,
					isResize: false,
					isDrag: false
			});
			m.show(); 
	 }
	</script>
</body>
</html>